import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { SGuildInfo } from "../../../../Message/Game/SGuildInfo";
import { GuildConfig } from "../../resource/GuildConfig";
import { GuildUtil } from "./info/GuildUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { PlayerOpRegister } from "../common/menu/PlayerOpRegister";
import { ColorConfig } from "../../resource/ColorConfig";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class GuildInfoWindow
    
    export  class GuildInfoWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._labelArray = Language.getString(57473).split(",");
            this._valueTxtArray = [];
            this._playerMiniInfo = new PlayerMiniInfo();
            this.setSize(325, 360);
            this.titleHeight = 28;
            this.title = Language.getString(57475);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            super.createChildren();
            ObjCreate.createFlowerBg(17, 39, 290, 310, this);
            var loc4=0;
            while (loc4 < this._labelArray.length) 
            {
                loc3 = this._labelArray[loc4] as string;
                loc1 = ObjCreate.createTextField(loc3, 85, 45 + loc4 * 20, 70, 20, this);
                loc1.autoSize = flash.text.TextFieldAutoSize.LEFT;
                if (loc4 != (this._labelArray.length - 1)) 
                {
                    loc2 = ObjCreate.createTextField("", 150, 45 + loc4 * 20, 70, 20, this);
                    loc2.autoSize = flash.text.TextFieldAutoSize.LEFT;
                    if (loc4 == 6) 
                    {
                        this._leaderNameTxt = loc2;
                    }
                    this._valueTxtArray.push(loc2);
                }
                ++loc4;
            }
            this._purposeInput = ObjCreate.createGTextInput(85, 210, 165, 75, this);
            this._tipTxt = ObjCreate.createTextField(Language.getString(57474), 0, 295, 325, 20, this, new GTextFormat("", 12, 65280));
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._applyBtn = ObjCreate.createGButton(Language.getString(57026), 140, 315, 70, 28, this);
            this._applyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onApplyBtnClickHandler);
            return;
        }

        public updateBySGuildInfo(arg1: SGuildInfo): void
        {
            var loc1=0;
            var loc3=null;
            this._guildInfo = arg1;
            var loc2=[];
            if (arg1) 
            {
                loc1 = GuildConfig.instance.getMaxNumByLevel(arg1.level) + GuildUtil.getRoomNumByLevel(arg1.house);
                loc2.push(HTMLUtil.addColor(arg1.guildName, "#f0ea3f"));
                loc2.push(HTMLUtil.addColor(Language.getStringByParam(57481, arg1.level), "#F1FFB1"));
                loc2.push(this.getCampName(arg1.camp));
                loc2.push(HTMLUtil.addColor(arg1.playerNum + "/" + loc1, "#F1FFB1"));
                loc2.push(HTMLUtil.addColor(arg1.money + "/" + arg1.maxMoney, "#F1FFB1"));
                loc2.push(HTMLUtil.addColor(Language.getStringByParam(57482, arg1.guildTreeLevel), GuildUtil.getGuildTreeColor(arg1.guildTreeLevel)));
                loc2.push(Language.getStringByParam(57483, arg1.leader.name));
                PlayerOpRegister.UnRegister(this._leaderNameTxt);
                this._playerMiniInfo.miniPlayer = arg1.leader;
                PlayerOpRegister.Register(this._leaderNameTxt, this._playerMiniInfo);
                this._purposeInput.text = arg1.purpose;
            }
            var loc4=0;
            while (loc4 < this._valueTxtArray.length) 
            {
                (loc3 = this._valueTxtArray[loc4] as Object /* flash.text.TextField */).htmlText = loc2[loc4].toString();
                ++loc4;
            }
            return;
        }

        public showApplyButton(arg1: Boolean): void
        {
            this._applyBtn.visible = arg1;
            return;
        }

        /* internal  */getCampName(arg1: int): string
        {
            return HTMLUtil.addColor(Language.getString(32052 + arg1), ColorConfig.instance.getCampColor(arg1).color);
        }

        /* internal  */onApplyBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._guildInfo) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildApply, {"guildId": this._guildInfo.guildId}));
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            return;
        }

        /* internal */ /* var */_purposeInput: GTextInput;

        /* internal */ /* var */_applyBtn: GButton;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_labelArray: Array<any>;

        /* internal */ /* var */_valueTxtArray: Array<any>;

        /* internal */ /* var */_leaderNameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_guildInfo: SGuildInfo;

        /* internal */ /* var */_playerMiniInfo: PlayerMiniInfo;
    }
